import { useReactive } from "ahooks";
import { useModel } from "umi";
import compress from "gql-compress";

const useDeleteProxyServer = () => {
    const { graphqlFetchPlatform } = useModel("global");

    const state = useReactive({
        loading: false,
    });

    const deleteProxyServer = async (proxyUuid, callback) => {
        state.loading = true;
        let res = await graphqlFetchPlatform({
            query,
            variables: { proxyUuid },
        });
        callback && callback(res);
        state.loading = false;
        return res;
    };

    return { ...state, deleteProxyServer };
};

const query = compress(`mutation MyMutation(
    $proxyUuid: UUID!
) {
    deleteProxyServerByProxyUuid(
        input: {
            proxyUuid: $proxyUuid
        }
    ) {
        clientMutationId
    }
}`);

export default useDeleteProxyServer;
